<template>
  <el-row :gutter="20" class="afterHome">
    <el-col :span="24">
      <!-- 公司信息 -->
      <companyInfo ref="companyInfo" />
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('项目现金流') }}</span>
          <el-link :underline="false" style="float: right;margin: 4px 0 0 10px;" @click="cashflowAdd">
            <i class="el-icon-plus" style="color: #007eff;" />
          </el-link>
          <div class="chartBtn">
            <el-select v-model="cashFlow" size="mini" style="width: 100px;margin-top: -4px;" @change="cashflowQuarterOrMonthChange">
              <el-option :label="$t('按月统计')" value="month" />
              <el-option :label="$t('按季统计')" value="season" />
            </el-select>
          </div>
        </div>
        <div class="text item" style="height: 300px;">
          <barLineChart v-if="optionData.datas.length > 0" height="100%" :chart-data="optionData" />
          <div v-else class="noneData">
            <div>
              <svg-icon icon-class="none" class-name="none-icon" />
              <p>{{ $t('暂无数据') }}</p>
            </div>
          </div>
        </div>
      </div>
    </el-col>
    <el-col :span="12">
      <div class="box" style="height: 350px">
        <div class="area-header">
          <span class="area-header-title">{{ $t('指标预警') }}</span>
        </div>
        <div class="text item">
          <PcwRiskMonitorInfo ref="PcwRiskMonitorInfo" :buss-id="companyId" />
        </div>
      </div>
    </el-col>
    <el-col :span="24">
      <otherInvestment ref="otherInvestment" />
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('新闻舆情') }}</span>
        </div>
        <div class="text item none-info">
          <company-news-info ref="companyNewsInfo" :buss-id="companyId" />
        </div>
      </div>
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('项目最新事件') }}</span>
          <span style="float: right;font-size: 13px;padding: 5px 0;">{{ $t('单位:元') }}</span>
        </div>
        <div style="height: 568px;">
          <dealEvent ref="dealEvent" :deal-id="businessId" />
        </div>
      </div>
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('最新股东') }}</span>
        </div>
        <div class="text item" style="height: 250px; overflow: auto;">
          <company-holder-info ref="companyHolderHnfo" :buss-id="companyId" />
        </div>
      </div>
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('融资历史') }}</span>
        </div>
        <div class="text item" style="height: 250px; overflow:auto;">
          <CompanyFinanceInfo ref="CompanyFinanceInfo" :buss-id="companyId" />
        </div>
      </div>
    </el-col>

    <el-col :span="24">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('财务关键指标') }}</span>
          <el-radio-group v-model="dataSource" size="mini" style="float: right;">
            <el-radio-button
              v-for="item in dataSourceOptions"
              :key="item.dictValue"
              :label="item.dictValue"
            >{{ $t(item.dictLabel) }}</el-radio-button>
          </el-radio-group>
        </div>
        <div class="text item">
          <PcwDataKeyInfo ref="PcwDataKeyInfo" :buss-id="companyId" :data-source="dataSource" />
        </div>
      </div>
    </el-col>
    <el-dialog :title="$t('项目估值')" :visible.sync="valuationOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealCompanyValuationForm ref="dealCompanyValuationForm" />
    </el-dialog>
    <el-dialog :title="$t('现金流')" :visible.sync="cashflowOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealCashflowForm ref="dealCashflowForm" />
    </el-dialog>
  </el-row>
</template>
<script>
  import dealCompanyValuationForm from '@/views/deal/companyvaluation/dealCompanyValuationForm'
  import dealCashflowForm from '@/views/deal/cashflow/dealCashflowForm'
  import otherInvestment from '@/components/Deal/otherInvestment'
  import { companyInfo } from '@/components/Deal'
  import CompanyNewsInfo from '@/components/Deal/companyNewsInfo'
  import CompanyHolderInfo from '@/components/Deal/companyHolderInfo'
  import CompanyFinanceInfo from '@/components/Deal/companyFinanceInfo'
  import PcwDataKeyInfo from '@/components/Deal/pcwDataKeyInfo'
  import PcwRiskMonitorInfo from '@/components/Deal/pcwRiskMonitorInfo'
  import dealEvent from '@/components/dealEvent'
  import { companyValuationChart } from '@/api/deal/companyvaluation/dealCompanyValuation'
  import { cashFlowCharts } from '@/api/deal/cashflow/dealCashflow'
  import barLineChart from '@/views/chart/barLineChart.vue'
  export default {
    components: {
      dealCompanyValuationForm,
      dealCashflowForm,
      barLineChart,
      companyInfo,
      CompanyNewsInfo,
      CompanyHolderInfo,
      CompanyFinanceInfo,
      PcwDataKeyInfo,
      PcwRiskMonitorInfo,
      otherInvestment,
      dealEvent
    },
    props: {
      busId: {
        type: String,
        default: () => ''
      },
      busType: {
        type: String,
        default: () => ''
      },
      childLeftMenu: {
        type: Array,
        default: () => []
      }
    },
    data() {
      return {
        statistical: 'month',
        cashFlow: 'month',
        companyId: this.$route.query.companyId,
        businessId: this.$route.query.id,
        // 关键条款弹出层
        dealTermsOpen: false,
        valuationOpen: false,
        cashflowOpen: false,
        chartData: {},
        optionData: {
          datas: []
        },
        show: false,
        showCash: false,
        dataSourceOptions: [],
        dataSource: 'act'
      }
    },
    created() {
      this.getDicts('pcw_data_source').then(response => {
        this.dataSourceOptions = response.data
      })
    },
    mounted() {
      this.valuationHandler('month')
      this.cashflowQuarterOrMonthChange('month')
    },
    methods: {
      cashflowAdd() {
        this.cashflowOpen = true
        this.$nextTick(() => {
          this.$refs.dealCashflowForm.init(null)
        })
      },
      valuationHandler(val) { // 估值信息图表
        let flag = false
        if (val === 'month') {
          flag = true
        }
        const params = {
          dealId: this.$route.query.id,
          quarterOrMonth: flag
        }
        companyValuationChart(params).then(response => {
          if (response.data != null) {
            this.show = true
            this.chartData = response.data
          } else {
            this.show = false
          }
        })
      },
      cashflowQuarterOrMonthChange(val) { // 项目现金流图表
        let flag = false
        if (val === 'month') {
          flag = true
        }
        const params = {
          dealId: this.$route.query.id,
          quarterOrMonth: flag
        }
        cashFlowCharts(params).then(response => {
          this.optionData = {
            legend: true,
            datas: [],
            yAxis2: false,
            yAxisName2: ' ',
            valueFormatter: true,
            legendLeft: 'center',
            xLabel: []
          }
          if (response.data != null) {
            this.optionData.xLabel = response.data.dateList
            this.optionData.datas = [
              {
                name: this.$t('正现金流'),
                type: 'bar',
                stack: '1',
                data: response.data.positiveCashFlowList
              },
              {
                name: this.$t('负现金流'),
                type: 'bar',
                stack: '1',
                data: response.data.negativeCashFlowList
              },
              {
                name: this.$t('现金流结余'),
                type: 'line',
                stack: '1',
                yAxisIndex: 0,
                data: response.data.cashFlowBalanceList
              }
            ]
          }
        })
      },
      openTermsTemplate() {
        this.$refs.refTerms.getListTerms()
      },
      openNews(row) {
        if (row.newUrl.indexOf('http://') !== -1) {
          window.open(row.newUrl)
        } else if (row.newUrl.indexOf('https://') !== -1) {
          window.open(row.newUrl)
        } else {
          window.open('http://' + row.newUrl)
        }
      }
    }
  }
</script>

<style scoped>

  .el-container{
    height: 100%;display: flex;
  }
  .fundMenu{
    top: 70px;
  }
  .voteMain{
    position: fixed;
    left: 200px;
    right: 0;
    bottom: 0;
    top: 60px;
    overflow: auto;
  }
  .box-card{
    margin-bottom: 20px;
  }
  .diyMain{
    margin-left: 200px;
  }
  .voteMain{
    padding: 20px;
  }
  .timeLine{
    overflow-y: auto;height: 370px; padding-left: 2px;
  }

</style>
